package nojava;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class MainWrite {
    public static void main(String[] args) throws Exception {
        System.out.println("请不断地输入你想说的 色眯眯的话: 以连续三个 '###' 结束输入 ");
        List<String> toSayList = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);
        while (true){
            String s = scanner.nextLine().trim();
            if(s.length()>0){
                if(s.equals("###")){
                    break;
                }
                toSayList.add(s);
            }
        }
        //输出到流
        DataOutputStream dos = new DataOutputStream( new FileOutputStream(getNewFile("d://情话")));
        dos.writeInt(toSayList.size());// 100
        for (int i = 0; i < toSayList.size(); i++) {
            dos.writeUTF(toSayList.get(i));
        }
        dos.flush();
        dos.close();
        System.out.println("OK");
    }

    private static File getNewFile(String path) throws IOException {
        File file = new File(path);
        if(file.exists()){
            file.delete();
        }
        file.createNewFile();
        return file;
    }
}
